function yyy=Calibrate_beta_d_I_delta_ksi_function(zzz)

beta=zzz(1);
d_I=zzz(2);

global w d_GIS ncity epsilon_weekday epsilon_weekend kappa E_weekday E_weekend H_R initial_infection gamma tau death_rate beta d_I delta_j delta_t

time=123; period=[1:1:time]; % until May 31

%% Actual Simulation
% setup dates: starting from Jan 30
Day = datetime(2020,1,30) + caldays(0:time);

% Initial Values
    Qtime(1,:,1)=initial_infection'; % Initial detected, as of January 30 (all looks exogenous)
    % city 8(1), 13(1), 15(1), 16(1) // 4 the detected
    Qtime(1,:,2)=zeros(1,25);
    Itime(1,:,1)=9*initial_infection';
    Itime(1,:,2)=zeros(1,25);
    for a=1:2
        for d1=1:ncity
            Ntime(1,d1,a)=H_R(d1,a);
            Stime(1,d1,a)=Ntime(1,d1,a)-Itime(1,d1,a)-Qtime(1,d1,a);
            Rtime(1,d1,a)=Ntime(1,d1,a)-Itime(1,d1,a)-Stime(1,d1,a)-Qtime(1,d1,a); % zero
            Ftime(1,d1,a)=death_rate(a)*Rtime(1,d1,a);
            Dtime(1,d1,a)=0;
            cum_Dtime(1,d1)=Qtime(1,d1,1)+Qtime(1,d1,2);
            cum_Dtime_14(1,d1)=Qtime(1,d1,1)+Qtime(1,d1,2);
        end
    end

% run simulation
for t=2:time
    [DayNumber,DayName] = weekday(Day(t));
    if DayNumber>=2 && DayNumber<=6 % weekdays
            [pi(t,:,:,:) d_ija(t,:,:,:)]=Calculate_pi_function(cum_Dtime_14(t-1,:));
                for d1=1:ncity
                    for a=1:2
                    S_dot(t,d1,a)=0;
                    for d2=1:ncity
                        S_dot(t,d1,a)=S_dot(t,d1,a)-beta*(sum(pi(t,:,d2,1).*Itime(t-1,:,1))+sum(pi(t,:,d2,2).*Itime(t-1,:,2)))/(sum(pi(t,:,d2,1).*(Ntime(t-1,:,1)-Qtime(t-1,:,1)))+sum(pi(t,:,d2,2).*(Ntime(t-1,:,2)-Qtime(t-1,:,2))))*(pi(t,d1,d2,a)*Stime(t-1,d1,a));
                    end
                    Stime(t,d1,a) =  Stime(t-1,d1,a) + S_dot(t,d1,a);
                    Itime(t,d1,a) =  Itime(t-1,d1,a)*(1 - gamma) - S_dot(t,d1,a) - d_I*Itime(t-1,d1,a);
                    Qtime(t,d1,a) =  Qtime(t-1,d1,a)*(1 - tau(a)) + d_I*Itime(t-1,d1,a);
                    Rtime(t,d1,a) =  Rtime(t-1,d1,a) + Itime(t-1,d1,a)*gamma + tau(a)*Qtime(t-1,d1,a);
                    Ftime(t,d1,a) =  death_rate(a)*Rtime(t,d1,a);
                    Ntime(t,d1,a) =  H_R(d1,a) - death_rate(a)*Rtime(t,d1,a);
                    Dtime(t,d1,a) = d_I*Itime(t-1,d1,a);
                    end
                    cum_Dtime(t,d1) = cum_Dtime(t-1,d1) + d_I*Itime(t-1,d1,1) + d_I*Itime(t-1,d1,2); % adding newly detected cases
                    cum_Dtime_14(t,d1) = sum(Dtime(max(1,t-13):t,d1,1))+sum(Dtime(max(1,t-13):t,d1,2));
                end
    else % weekends
            [pi(t,:,:,:) d_ija(t,:,:,:)]=Calculate_pi_weekend_function(cum_Dtime_14(t-1,:));
                for d1=1:ncity
                    for a=1:2
                    S_dot(t,d1,a)=0;
                    for d2=1:ncity
                        S_dot(t,d1,a)=S_dot(t,d1,a)-beta*(sum(pi(t,:,d2,1).*Itime(t-1,:,1))+sum(pi(t,:,d2,2).*Itime(t-1,:,2)))/(sum(pi(t,:,d2,1).*(Ntime(t-1,:,1)-Qtime(t-1,:,1)))+sum(pi(t,:,d2,2).*(Ntime(t-1,:,2)-Qtime(t-1,:,2))))*(pi(t,d1,d2,a)*Stime(t-1,d1,a));
                    end
                    Stime(t,d1,a) =  Stime(t-1,d1,a) + S_dot(t,d1,a);
                    Itime(t,d1,a) =  Itime(t-1,d1,a)*(1 - gamma) - S_dot(t,d1,a) - d_I*Itime(t-1,d1,a);
                    Qtime(t,d1,a) =  Qtime(t-1,d1,a)*(1 - tau(a)) + d_I*Itime(t-1,d1,a);
                    Rtime(t,d1,a) =  Rtime(t-1,d1,a) + Itime(t-1,d1,a)*gamma + tau(a)*Qtime(t-1,d1,a);
                    Ftime(t,d1,a) =  death_rate(a)*Rtime(t,d1,a);
                    Ntime(t,d1,a) =  H_R(d1,a) - death_rate(a)*Rtime(t,d1,a);
                    Dtime(t,d1,a) = d_I*Itime(t-1,d1,a);
                    end
                    cum_Dtime(t,d1) = cum_Dtime(t-1,d1) + d_I*Itime(t-1,d1,1) + d_I*Itime(t-1,d1,2); % adding newly detected cases
                    cum_Dtime_14(t,d1) = sum(Dtime(max(1,t-13):t,d1,1))+sum(Dtime(max(1,t-13):t,d1,2));
                end
    end
end

cum_Dtime_in_two_month=cum_Dtime(123,:)';
target1=(sum(cum_Dtime_in_two_month)-861)/861*100; % beta

Itime_sum=Itime(:,:,1)+Itime(:,:,2);
Qtime_sum=Qtime(:,:,1)+Qtime(:,:,2);
fraction=sum(Itime_sum,2)./(sum(Qtime_sum,2)+sum(Itime_sum,2)); % Our primary estimates for the fraction of infections that are undetected range from 88.7% to 93.6%. (Iceland)
target2=(mean(fraction(1:123))-0.9)/0.9*100; % new target 90%

sum(cum_Dtime_in_two_month)
mean(fraction(1:123))
yyy=(abs(target1)+abs(target2))/2
end